<?php
session_start();
header("Content-type: text/javascript");

$include = explode('--',$_GET['include']);

$alink = explode('|',$include[0]);
$url_base = $alink[0];
$url_prefix = $alink[1];

$atype = explode('|',$include[1]);
$app = $atype[0];
$com = $atype[1];


$a_link = 'var alink=["';
foreach($alink as $_v){
	if(!empty($_v))
	$a_link .= $_v.'","';
}

print(
    substr($a_link,0,-2).']; 
    var url_base = alink[0]; 
    var url_prefix = alink[1];'
);

$atype = explode('|',$include[1]);
print('
    var dir_lang = "'.$_SESSION['dir_lang'].'";
    var app="'.$atype[0].'";
    var com="'.$atype[1].'";
');
echo ' 
    var route = "'.$include[4].'";
    var _seokey = route.split("/");
';

print('
    include_javaScript(url_prefix+\'app/admin/view/temp/default/layout/js/jquery.js\');
	include_javaScript(url_prefix+\'app/admin/view/temp/default/layout/js/jquery-ui.js\');
    include_javaScript(url_prefix+\'app/\'+app+\'/view/lang/\'+dir_lang+\'/js/lang.js\');
    include_javaScript(url_prefix+\'app/\'+app+\'/view/temp/default/layout/js/script.js\');
	include_javaScript(url_prefix+\'app/admin/view/temp/default/layout/js/highslide.js\');
');

$libjs = explode('|',$include[3]);
foreach($libjs as $_fjs){
    $file_name =  realpath('../'. 'app/'.$app.'/view/temp/default/layout/js/'.$_fjs.'.js');
	if(!empty($_fjs) && file_exists($file_name)){
    	echo 'include_javaScript(url_prefix+\'app/\'+app+\'/view/temp/default/layout/js/'.$_fjs.'.js\');';
    }
}

/***load js default cho phan com****/
$file_name =  realpath('../'. 'app/'.$app.'/view/temp/default/'.$com.'/'.$com.'.js');
if(file_exists($file_name)){
    echo '    
        include_javaScript(url_prefix+\'app/\'+app+\'/view/temp/default/\'+com+\'/\'+com+\'.js\'); 
    
    ';
}

/**load js default cho phan module****/
$amod = explode('|',$include[2]);
foreach($amod as $_m){
    $file_name =  realpath('../'. 'app/'.$app.'/view/temp/default/module/'.$_m.'/'.$_m.'.js');
	if(!empty($_m) && file_exists($file_name)){
    	echo 'include_javaScript(url_prefix+\'app/\'+app+\'/view/temp/default/module/'.$_m.'/'.$_m.'.js\');';
    }
}

print('
    function include_javaScript(js_file)
    {
    	document.write(\'<script type="text/javascript" src="\'+ js_file + \'"></script>\');
    }
');